<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改医院</title>
<head>
<meta charset="utf-8">
<title>修改医院</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">

<link rel="stylesheet"
	href="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/css/layui.css"
	media="all" />
<link rel="stylesheet"
	href="/fdoctor-ms/statics/beginnerAdmin/plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet"
	href="/fdoctor-ms/statics/beginnerAdmin/css/btable.css" />
<link rel="stylesheet"
	href="/fdoctor-ms/statics/css/global.css" />
<link rel="stylesheet"
	href="/fdoctor-ms/statics/ztree/css/metroStyle/metroStyle.css" />
<link rel="stylesheet"
	href="/fdoctor-ms/statics/ztree/css/demo.css" />

<script type="text/javascript"
	src="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/layui.js"></script>
<script type="text/javascript"
	src="/fdoctor-ms/statics/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="/fdoctor-ms/statics/js/inputTools.js"></script>
<script type="text/javascript" src="/fdoctor-ms/statics/ztree/js/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="/fdoctor-ms/statics/ztree/js/jquery.ztree.excheck.min.js"></script>
<%
	String webServerIp = PropertiesUtils.getValue("ftp_web_server_ip");
%>
</head>

<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 5px; margin-left: 5px; margin-right: 5px">
		<legend>修改医院 </legend>
	</fieldset>
	<input type="hidden" id="webServerIp" value="<%=webServerIp%>">
	<form class="layui-form" action="" id="dataForm">
	<input type="hidden" id="id" value="${id}">
		<div class="layui-form-item" style="width: 100%">
			<label class="layui-form-label">区划</label>
				<div class="layui-input-inline" style="width:150px;">
				<select name="oneLevel" id="oneLevel"  lay-verify="" lay-filter="oneLevel" >
					  <option value="0">--请选择市(州)--</option>
				      	<c:forEach items="${oneList}" var="item">
				      		<option value="${item.regionCode}" <c:if test="${item.regionCode eq one}">selected</c:if>>${item.name}</option>
				      	</c:forEach>
					</select>     
			    </div>
			  	<div class="layui-input-inline" style="width:150px;">
			    <select name="twoLevel" id="twoLevel"  lay-verify="" lay-filter="twoLevel">
					  <option value="0">--请选择县(区)--</option>
					  	<c:forEach items="${twoList}" var="item">
				      		<option value="${item.regionCode}" <c:if test="${item.regionCode eq two}">selected</c:if>>${item.name}</option>
				      	</c:forEach>
					</select>     
			    </div>
			    <div class="layui-input-inline" style="width:150px;">
			     <select name="threeLevel" id="threeLevel"  lay-verify="" lay-filter="threeLevel">
					  <option value="0">--请选择镇(乡)--</option>
					  	<c:forEach items="${threeList}" var="item">
				      		<option value="${item.regionCode}" <c:if test="${item.regionCode eq three}">selected</c:if>>${item.name}</option>
				      	</c:forEach>
					</select>    
			    </div>
			    <div class="layui-input-inline" style="width:150px; margin-left: 110px; margin-top: 20px;">
			     <select name="fourLevel" id="fourLevel"  lay-verify="" lay-filter="fourLevel" >
					  <option value="0" >--请选择卫生院(村)--</option>
					  	<c:forEach items="${fourList}" var="item">
				      		<option value="${item.regionCode}" <c:if test="${item.regionCode eq four}">selected</c:if>>${item.name}</option>
				      	</c:forEach>
					</select>    
			    </div>
			 </div>
			 </br>
			<div class="layui-form-item" style="width: 100%">
				<label class="layui-form-label">医院名</label>	
				<div class="layui-input-inline">
			      <input name="orgName" class="layui-input" type="text" id="orgName" style="width:250px;" value="${hosEntity.orgName}">   
			    </div>
			</div>
			</br>
			<div class="layui-form-item" style="width: 100%">
				<label class="layui-form-label">医院地址</label>	
				<div class="layui-input-inline">
			      <input name="address" class="layui-input" type="text" id="address" style="width:400px;" value="${hosEntity.address}">   
			    </div>
			</div>
		</div>	
		</br>
		<hr><hr>
	  <div align="center">
	  		<button class="layui-btn layui-btn-big layui-btn-primary layui-btn-radius" type="button" id="saveButton"><i class="layui-icon">&#xe618;</i>确认保存</button>
	  </div>
	</form>


<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
	<ul id="deptTree" class="ztree"></ul>
</div>

</body>
<script type="text/javascript">
	//初始化表单控件
	layui.use(
		[ 'jquery', 'form', 'laydate','upload' ],
		function() {
			$ = layui.jquery;
			form = layui.form();
			var laydate = layui.laydate;
	
			
			//给联动下拉框声明选中事件
		     form.on('select(oneLevel)', function(data) {
		    	 if(data.value != '0'){
		    		 $.ajax({
				 			type : 'GET',
				 			url : '/fdoctor-ms/hospital/getChild',
				 			data : {
				 				regionCode : data.value
				 			},
				 			success : function(data) {
				 				var proHtml = '';
				 				for(i = 0; i < data.length; i++){
				 					proHtml += '<option value="'+data[i].regionCode+'">'+data[i].name+'</option>';
				 				}
				 				$('#twoLevel').html('<option value="0">--请选择县(区)--</option>');
				 				$('#twoLevel').append(proHtml);
				 				form.render();
				 			}
				 	});
		    	 }else{
		    		 $('#twoLevel').html('<option value="0">--请选择上级--</option>');
		    		 form.render();
		    	 }
		     });
		   
		     form.on('select(twoLevel)', function(data) {
		    	 if(data.value != '0'){
		    		 $.ajax({
				 			type : 'GET',
				 			url : '/fdoctor-ms/hospital/getChild',
				 			data : {
				 				regionCode : data.value
				 			},
				 			success : function(data) {
				 				var proHtml = '';
				 				for(i = 0; i < data.length; i++){
				 					proHtml += '<option value="'+data[i].regionCode+'">'+data[i].name+'</option>';
				 				}
				 				$('#threeLevel').html('<option value="0">--请选择镇(乡)--</option>');
				 				$('#threeLevel').append(proHtml);
				 				form.render();
				 			}
				 	});
		    	 }else{
		    		 $('#threeLevel').html('<option value="0">--请选择上级--</option>');
		    		 form.render();
		    	 }
		     });
		     
		     form.on('select(threeLevel)', function(data) {
		    	 if(data.value != '0'){
		    		 $.ajax({
				 			type : 'GET',
				 			url : '/fdoctor-ms/hospital/getChild',
				 			data : {
				 				regionCode : data.value
				 			},
				 			success : function(data) {
				 				var proHtml = '';
				 				for(i = 0; i < data.length; i++){
				 					proHtml += '<option value="'+data[i].regionCode+'">'+data[i].name+'</option>';
				 				}
				 				$('#fourLevel').html('<option value="0">--请选择卫生院(村)--</option>');
				 				$('#fourLevel').append(proHtml);
				 				form.render();
				 			}
				 	});
		    	 }else{
		    		 $('#fourLevel').html('<option value="0">--请选择上级--</option>');
		    		 form.render();
		    	 }
		     });
			
			$('#saveButton').on('click', function(){
				var oneL=$('#oneLevel').val();
				var twoL=$('#twoLevel').val();
				var threeL=$('#threeLevel').val();
				if(threeL==0){
					if(twoL==0){
						if(threeL==0){
							layer.msg('请选择区划！',{icon: 7});
				    		return;
						}
					}
				}
				if($('#orgName').val() == null || $('#orgName').val() == ''){
					layer.msg('请输入医院名称！',{icon: 7});
		    		return;
				}
				if($('#address').val() == null || $('#address').val() == ''){
					layer.msg('请输入医院地址！',{icon: 7});
		    		return;
				}
				
				$.ajax({
			 			type : 'POST',
			 			url : '/fdoctor-ms/hospital/updateHos',
			 			data : packParams(),
			 			success : function(data) {
			 				if(data.code == 200){
			 					var index = parent.layer.getFrameIndex(window.name);
			 					parent.layer.close(index);
			 					parent.layer.msg('保存成功！',{icon: 1});
			 					parent.tableConfig();
			 				}else{
			 					parent.layer.msg(data.msg,{icon: 2});
			 				}
			 			}
			 		});
       			});
			})
			function packParams(){
				var oneL=$('#oneLevel').val();
				var twoL=$('#twoLevel').val();
				var threeL=$('#threeLevel').val();
				var fourL=$('#fourLevel').val();
				if(fourL!='0'){
					regionCode=fourL;
				}else if(threeL!='0'){
					regionCode=threeL;
				}else if(twoL!='0'){
					regionCode=twoL;
				}else{
					regionCode=oneL;
				}
				var param = {
						id:$('#id').val(),
		    			regionCode:regionCode,
		    			orgName:$('#orgName').val(),
		    			address:$('#address').val()
				}
				return param;
			}
		
</script>
</html>